package com.example.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.domain.CustomRequire;


@Repository
public interface CustomRequireMapper extends BaseMapper<CustomRequire>{
	 /**
     * 查询所有
     * @return
     */
    @Select("select * from custom_require")
    @Results({
    	@Result(property = "createTime",column = "create_time"),
    	@Result(property = "pjName",column = "pj_name"),
    	@Result(property = "provideName",column = "provide_name"),
    	})
    Page<CustomRequire> findAll(Page page);
    
    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Select("select * from custom_require where id = #{id}")
    @Results({
    	@Result(property = "pjName",column = "pj_name"),
    	@Result(property = "provideName",column = "provide_name"),
    	})
    CustomRequire findById(Integer id);

    /**
     * 更新
     * @param custom_require
     */
    @Update("update custom_require set name=#{name} where id=#{id}")
    void update(CustomRequire customRequire);

    /**
     * 删除
     * @param id
     */
    @Delete("delete from custom_require where id=#{id}")
    void delete(Integer id);

    /**
     * 增加
     * @param 
     */
    @Results({
    	@Result(property = "pjName",column = "pj_name"),
    	@Result(property = "provideName",column = "provide_name"),
    	})
    @Insert("insert into custom_require(pj_name,provide_name,name,money,date,batch,number,state) "
    		+ "values(#{pjName},#{provideName},#{name},#{money},#{date},#{batch},#{number},#{state})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    int add(CustomRequire customRequire);
    
    /**
     * 审核
     * @param id
     * @param state
     */
    @Update("update custom_require set state=#{state} where id=#{id}")
    void audit(String id, String state);
    
    
}
